// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class ORDER_DETAIL_SUPPLEMENT_RAS_O17 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("35 NTE",35)]
  	    [HL7Field(HL7Version.v24, 35, HL7Repeat.True, HL7Required.True,"NTE")]
	    public NTE[] NTE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("38 RXR",38)]
  	    [HL7Field(HL7Version.v24, 38, HL7Repeat.True, HL7Required.True,"RXR")]
	    public RXR[] RXR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("40 COMPONENTS",40)]
  	    [HL7Field(HL7Version.v24, 40, HL7Repeat.False, HL7Required.False,"COMPONENTS_RAS_O17")]
	    public COMPONENTS_RAS_O17 COMPONENTS {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
			RXR = PopSegmentParseAndCheckRequiredArray<RXR>(availableData, options, "RXR");
			COMPONENTS = ProcessGroup<COMPONENTS_RAS_O17>(availableData, options, "COMPONENTS");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isNTE = availableData.StartsWith("NTE", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("NTE", options.Version) || isNTE) {
				return isNTE;
			}
			bool isRXR = availableData.StartsWith("RXR", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("RXR", options.Version) || isRXR) {
				return isRXR;
			}
			COMPONENTS_RAS_O17 testCOMPONENTS_RAS_O17 = new COMPONENTS_RAS_O17();
			bool grpCCCOMPONENTS_RAS_O17 = (testCOMPONENTS_RAS_O17.CanConsume(availableData, options));
			if (IsRequired("COMPONENTS", options.Version) || grpCCCOMPONENTS_RAS_O17) {
				return grpCCCOMPONENTS_RAS_O17;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "ORDER_DETAIL_SUPPLEMENT";
			}
        }

        static ORDER_DETAIL_SUPPLEMENT_RAS_O17() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(ORDER_DETAIL_SUPPLEMENT_RAS_O17));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (NTE != null && NTE.Length > 0) {
			for (int i = 0; i < NTE.Length; i++) {
				string segmentValue = NTE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (RXR != null && RXR.Length > 0) {
			for (int i = 0; i < RXR.Length; i++) {
				string segmentValue = RXR[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (COMPONENTS != null) {
			string segmentValue = COMPONENTS.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

